package com.itheima.homework.Five;

import java.util.Arrays;
import java.util.Comparator;

public class Demo {

    public static void main(String[] args) {


        Student[] stu = new Student[4];
        Student student1 = new Student("张三",18,180.0);
        Student student2 = new Student("李四",25,175.0);
        Student student3 = new Student("王五",19,178.0);
        Student student4 = new Student("老六",34,189.2);

        stu[0] = student1;
        stu[1] = student2;
        stu[2] = student3;
        stu[3] = student4;

//        匿名内部类
        Arrays.sort(stu, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {

                int age = o1.getAge();
                int age1 = o2.getAge();
                int result = age - age1;
                return result;
            }
        });

//        Lambda标准格式
        Arrays.sort(stu, (Student o1,Student o2) -> {

            int age = o1.getAge();
            int age1 = o2.getAge();
            int result = age - age1;
            return result;
        });

//          简化格式
        Arrays.sort(stu, (o1, o2) -> {

            int age = o1.getAge();
            int age1 = o2.getAge();
            int result = age - age1;
            return result;
        });
    }
}
